*Table A.32: Means of baseline BMI for those present at the start and in year 3
cd ""

use master_data_adults_child_s13456_shared.dta, clear

*BMI
*Calculate z-scores for BMI
egen gendermax=max(gender), by(id_nb)
ge sex=(gendermax==1) 
replace sex=. if gendermax==.

drop zbmi pzbmi
egen zbmi = zanthro(bmi,ba,UK), xvar(months) gender(sex) gencode(male=1, female=0) ageunit(month)
gen pzbmi=normal(zbmi)

ge overw_obese_child=(pzbmi>=0.85)
replace overw_obese_child=. if pzbmi==.  

ge uwgt_child=(pzbmi<=0.02)
replace uwgt_child=. if pzbmi==.

*
ge food15_other_veg_new=food15_other_veg
replace food15_other_veg_new=0 if food15_other_veg==. & energykcal!=.
ge food16_fruit_new=food16_fruit
replace food16_fruit_new=0 if food16_fruit==. & energykcal!=.

su food15_other_veg 
su food16_fruit 
su food15_other_veg_new 
su food16_fruit_new

*
drop portion_veg_wisp portion_fruit_wisp
gen portion_veg_wisp=food15_other_veg/80
gen portion_fruit_wisp=food16_fruit/80
gen fuit_and_veg_g=total_veg_fruit_eatwell if session==1
replace fuit_and_veg_g=total_veg_fruit_eatwell if session==3
replace fuit_and_veg_g=food15_other_veg+food16_fruit if session==4

ge FV=food15_other_veg_new+food16_fruit_new

keep id id_nb child treatment session energykcal food15_other_veg_new food16_fruit_new totalfatg saturatesg sugarsg nmesg pzbmi bmi_cat bmi fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese FV

ge t=1 if session==1
replace t=2 if session==3
replace t=3 if session==4
replace t=4 if session==5
replace t=5 if session==6

merge 1:1 id t using "panel.dta"

egen child1=max(child), by(id)
drop child
rename child1 child

drop if t==.
drop session
drop _merge

ge pres_24hr=1 if food16_fruit_new!=.
replace pres_24hr=0 if  food16_fruit_new==.
egen count_sum_24hr=sum(pres_24hr), by(id)

ge pres_bmi=1 if bmi_cat!=.
replace pres_bmi=0 if  bmi_cat==.
egen count_sum_bmi=sum(pres_bmi), by(id)

ge pres_fp=1 if fp_veg!=.
replace pres_fp=0 if  fp_veg==.
egen count_sum_fp=sum(pres_fp), by(id)

gen count_all=count_sum_fp+count_sum_bmi+count_sum_24hr
drop if count_all==0

sort count_all

reshape wide pres_24hr pres_bmi pres_fp treatment child pzbmi energykcal food15_other_veg_new food16_fruit_new totalfatg saturatesg sugarsg nmesg bmi_cat bmi fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese FV, i(id_nb) j(t)


***BMI
**Children
*Control
foreach x in pzbmi1 {
su `x' 
reg `x' if child1==1 & pres_bmi1==1 & (treatment1==1)
est store eq1
reg `x' if child1==1 & pres_bmi5==1 & (treatment1==1)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}


*Meal
foreach x in pzbmi1 {
su `x' 
reg `x' if child1==1 & pres_bmi1==1 & (treatment1==2)
est store eq1
reg `x' if child1==1 & pres_bmi5==1 & (treatment1==2)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}

*Snack
foreach x in pzbmi1 {
su `x' 
reg `x' if child1==1 & pres_bmi1==1 & (treatment1==3)
est store eq1
reg `x' if child1==1 & pres_bmi5==1 & (treatment1==3)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}


**Adults
*Control
foreach x in bmi1 {
su `x' 
reg `x' if child1==0 & pres_bmi1==1 & (treatment1==1)
est store eq1
reg `x' if child1==0 & pres_bmi5==1 & (treatment1==1)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}


*Meal
foreach x in bmi1 {
su `x' 
reg `x' if child1==0 & pres_bmi1==1 & (treatment1==2)
est store eq1
reg `x' if child1==0 & pres_bmi5==1 & (treatment1==2)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}

*Snack
foreach x in bmi1 {
su `x' 
reg `x' if child1==0 & pres_bmi1==1 & (treatment1==3)
est store eq1
reg `x' if child1==0 & pres_bmi5==1 & (treatment1==3)
est store eq2
suest eq1 eq2
lincom [eq1_mean]_cons - [eq2_mean]_cons
}
